﻿<%@ page import="com.cai.entity.User" %>
<%@ page import="java.util.List" %>
<%@ page import="com.cai.dao.UserDao" %>
<%@ page import="com.cai.dao.impl.UserDaoImpl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    UserDao userDao = new UserDaoImpl();
    List<User> list = userDao.userQueryAll();
    request.setAttribute("userList", list);
%>
<head>
    <title>发送消息</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="style/adminStyle.css" rel="stylesheet" type="text/css"/>
    <script src="js/jquery.js"></script>
    <script src="js/public.js"></script>
</head>
<body>
<div class="wrap">
    <div class="page-title">
        <span class="modular fl"><i class="user"></i><em>发送消息</em></span>
    </div>
    <dl>
        <dt id="SendUser" class="R-userTitle" hidden>${sessionScope.user}</dt>
        <dt class="R-userTitle">接收者:</dt>
        <select id="ReturnUser" class="inline-select">
            <option hidden disabled selected>--请选择--</option>
            <c:forEach var="user" items="${requestScope.userList}">
                <option value="${user.user_name}">${user.user_name}</option>
            </c:forEach>
        </select>
    </dl>
    <div>
        <textarea placeholder="请输入留言..." class="textarea block" id="send_textarea" style="padding:1em;"></textarea>
        <input type="button" value="发送留言 " class="tdBtn" style="margin:8px 0;"/>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $("input[type=button]").click(function () {
            var SendUser=$("#SendUser").text()
            var sendText=$("#send_textarea").val()
            var ReturnUser=$("#ReturnUser").val()
            $.ajax({
                url:"/cai/SendMessage",
                type:"post",
                data:{
                    "sendUser":SendUser,
                    "sendText":sendText,
                    "returnUser":ReturnUser
                },
                success:function (data) {
                    if (parseInt(data)===1){
                        location.href="user_message.jsp"
                    }else {
                        alert("发送消息失败")
                    }
                }
            })
        })
    })
</script>
</body>
</html>